package com.campusevaluation.domain.po;

import cn.hutool.core.lang.UUID;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "问卷实体类")
@Document(collection = "questionnaire")
public class Questionnaire implements Serializable {
    @Id
    private String id = "Q-" + UUID.randomUUID().toString();

    // 问卷标题
    private String title;

    // 问卷描述
    private List<String> content;

    // 创建者ID
    private Long creatorId;

    // 适用部门
    private List<Long> departments;

    // 问卷问题
    private List<Question> questions;

    // 是否被发布
    private Boolean isPublished;

    @Field("valid_from")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date validFrom;

    @Field("valid_to")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date validTo;

    @CreatedDate
    @Field("create_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;

    @LastModifiedDate
    @Field("update_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Question {
        private String id;
        // 问题类型
        private Integer type;
        // 问题描述
        private List<String> content;
        // 问题选项，选择与多选
        private List<String> options;
        // 是否必填
        private Boolean isMust;
        // 填空限制
        private Integer limit;
    }
}
